/*
 * Peony-Qt's Library
 *
 * Copyright (C) 2023, KylinSoft Co., Ltd.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this library.  If not, see <https://www.gnu.org/licenses/>.
 *
 */

#include "pathbar.h"
#include <PeonyPathCompleter>
#include <PeonyPathBarModel>
#include <QDebug>
#include <QObject>
#include <peony-qt/file-utils.h>
#include "debug.h"

FileDialogPathBar::FileDialogPathBar(QWidget *parent) : QWidget(parent)//Peony::AdvancedLocationBar(parent)//QLineEdit(parent)//
{
    setAttribute(Qt::WA_TranslucentBackground);
    setContentsMargins(0,0,0,0);
    m_pathBar = new Peony::AdvancedLocationBar(this);
    m_pathBar->setFixedWidth(this->width());
    m_pathBar->setGeometry(0, (this->height() - m_pathBar->height()) / 2, this->width(), m_pathBar->height());
}

FileDialogPathBar::~FileDialogPathBar()
{
    m_pathBar->deleteLater();
    m_pathBar = nullptr;
}

void FileDialogPathBar::updatePath(const QString &uri)
{
    pDebug << "m_pathBar........ updatePath:" << uri << Peony::FileUtils::getEncodedUri(uri);
    m_pathBar->updateLocation(Peony::FileUtils::urlEncode(uri));
//    setText(uri);
//    clearFocus();
}

void FileDialogPathBar::resizeEvent(QResizeEvent *e)
{
    m_pathBar->setFixedWidth(this->width());
    m_pathBar->setGeometry(0, (this->height() - m_pathBar->height()) / 2, this->width(), m_pathBar->height());
}

Peony::AdvancedLocationBar *FileDialogPathBar::getPathBar()
{
    return m_pathBar;
}
